<!DOCTYPE html>
<html lang="zh-CN">
	<head>
		<meta charset="UTF-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>scrollWidth/Height</title>
		<style>
			#box {
				width: 100px;
				height: 100px;
				padding: 10px;
				border: 30px solid red;
				overflow-y: auto;
			}
		</style>
	</head>
	<body>
		<div id="box">
			Lorem ipsum, dolor sit amet consectetur adipisicing elit. Rerum molestias et repudiandae consequatur sit quod
			omnis, labore eum vero incidunt cumque commodi itaque officiis? Nemo exercitationem repellendus officiis dolorum
			soluta?
		</div>

		<br />

		<button onclick="hanlerClick()">完全展开至内容宽高</button>

		<script>
			// scrollWidth/Height 获取元素的整体宽度和高度（包括滚动出的部分宽高）
			console.log(box.scrollWidth) // 133
			console.log(box.scrollHeight) // 566

			hanlerClick = () => {
				box.style.width = box.scrollWidth + 'px'
				box.style.height = box.scrollHeight + 'px'
			}
		</script>
	</body>
</html>
